﻿using System.Collections.Generic;
using System.Linq;
using DeltaGroup.WheelOfJeopardy.GameManager;
using DeltaGroup.WheelOfJeopardy.Model;
using DeltaGroup.WheelOfJeopardy.UI.ViewModel;
using DeltaGroup.WoJ.Tests.Stub;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace DeltaGroup.WoJ.Tests.GameManagerTests
{
    
    
    /// <summary>
    ///This is a test class for GameTest and is intended
    ///to contain all GameTest Unit Tests
    ///</summary>
    [TestClass()]
    public class GameTest
    {
        private Mock<IChallengeManager> _challengeManager;
        private Game _game;
        private SetupModel _setup;
        
        [TestInitialize]
        public void Initialize()
        {
            Game.Settings = new StubGameSettings();

            _challengeManager = new Mock<IChallengeManager>();
            _setup = new SetupModel();


            var challengeSet = new ChallengeSet()
                                    {
                                        JeopardyCategories = BuildChallenges(),
                                        DoubleJeopardyCategories = BuildChallenges(),
                                        FinalJeopardyChallenge = new Challenge()

                                    };
            _challengeManager.Setup(x => x.GetChallenges(It.IsAny<string>())).Returns(challengeSet);
        }
        
        [TestMethod]
        public void Assign_One_Daily_Double_To_Jeopardy()
        {
            CreateGame();

            var result = _game.Jeopardy.Categories.SelectMany(x => x.Challenges).Count(x => x is DailyDouble);

            Assert.AreEqual(1, result);
        }
        [TestMethod]
        public void Assign_Two_Daily_Double_To_Double_Jeopardy()
        {
            CreateGame();

            var result = _game.DoubleJeopardy.Categories.SelectMany(x => x.Challenges).Count(x => x is DailyDouble);

            Assert.AreEqual(2, result);
        }
        [TestMethod]
        public void Set_Game_Current_To_Created_Game()
        {
            CreateGame();

            Assert.AreEqual(_game, Game.Current);
        }

        private void CreateGame()
        {
            _game = Game.New(_setup, _challengeManager.Object);
        }
        private List<Category> BuildChallenges()
        {
            var categories = new List<Category>();
            for (var i = 0; i < 6; i++)
            {
                var category = new Category {Title = "test" + i, Challenges = new List<Challenge>()};
                for (var j = 0; j < 5; j++)
                {
                    var challenge = new Challenge {Point = (j + 1)*100, Prompt = "test prompt " + j, Category = category.Title};
                    category.Challenges.Add(challenge);
                }
                categories.Add(category);
            }
            return categories;
        }
    }
}
